<template>
  <div class="breadcrumb">
    <el-breadcrumb :separator-icon="ArrowRight">
      <transition-group name="breadcrumb">
        <el-breadcrumb-item
          v-for="(item, index) in breadcrumbList"
          :key="item.path"
        >
          <div @click="onBreadcrumbClick(item, index)">
            <i class="iconfont" :class="item.meta.icon"></i>
            <span>{{ item.meta.title }}</span>
          </div>
        </el-breadcrumb-item>
      </transition-group>
    </el-breadcrumb>
  </div>
</template>

<script setup lang="ts">
import { computed } from "vue";
// import { HOME_URL } from "@/config";
import { useRoute, useRouter } from "vue-router";
import { ArrowRight } from "@element-plus/icons-vue";
// import { useAuthStore } from "@/stores/modules/auth";
import { useAuthStore } from "@/stores/";

// import { useGlobalStore } from "@/stores/modules/global";

const HOME_URL = "/home";

const route = useRoute();
const router = useRouter();
const authStore = useAuthStore();
// const globalStore = useGlobalStore();

const breadcrumbList = computed(() => {
  let breadcrumbData =
    authStore.breadcrumbListGet[route.matched[route.matched.length - 1].path] ??
    [];
  // 🙅‍♀️不需要首页面包屑可删除以下判断
  if (breadcrumbData[0].path !== HOME_URL) {
    breadcrumbData = [
      { path: HOME_URL, meta: { icon: "icon-shouye1", title: "首页" } },
      ...breadcrumbData,
    ];
  }
  return breadcrumbData;
});

// Click Breadcrumb
const onBreadcrumbClick = (item: Menu.MenuOptions, index: number) => {
  if (index !== breadcrumbList.value.length - 1) router.push(item.path);
};
</script>

<style scoped lang="less">
.breadcrumb {
  .iconfont {
    margin-right: 5px;
    font-size: 14px;
  }
}
</style>
